package com.by.controller.sys;

import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.controller.BaseController;
import com.by.entity.sys.Role;
import com.by.service.sys.RoleService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/role")
public class RoleController extends BaseController {

    @Autowired
    RoleService roleService;

    @PostMapping("/save")
    public ResultBean save(@RequestBody Role role) {
        int rs = roleService.save(role);
        return rs == 1 ? success("保存成功") : fail("保存失败");
    }

    @PostMapping("/query")
    public ResultBean query() {
        PageBean bean = roleService.query(null);
        return success("角色列表", bean);
    }

    @GetMapping("/auth")
    public ResultBean queryAuth(String id) {
        List list = roleService.queryAuth(id);
        return success("角色权限", list);
    }

    @PutMapping("/update")
    public ResultBean update(@RequestBody Role role) {
        int rs = roleService.update(role);
        return rs == 1 ? success("修改成功") : fail("修改失败");
    }

    @DeleteMapping("/delete")
    public ResultBean delete(String id) {
        int rs = roleService.deleteLogic(id);
        return rs == 1 ? success("删除成功") : fail("删除失败");
    }

    @GetMapping("/all")
    public ResultBean queryRole() {
        List list = roleService.queryRole();
        return success("角色", list);
    }

}
